package com.scuec.tourismwebsite.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.WeatherForecast;
import com.scuec.tourismwebsite.service.WeatherForecastService;
import com.scuec.tourismwebsite.vo.ViewWeatherForecastWithCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/weather-forecast")
@CrossOrigin
public class WeatherForecastController {

    @Autowired
    private WeatherForecastService weatherForecastService;

    @GetMapping("/page")
    public PageInfo<ViewWeatherForecastWithCity> getWeatherforecastPages(Integer pageNum,Integer pageSize) {
        PageInfo<ViewWeatherForecastWithCity> pageInfo=weatherForecastService.findWeatherForecastPages(pageNum,pageSize);
        return pageInfo;
    }
    @GetMapping("/query")
    public List<ViewWeatherForecastWithCity> findWeatherForecastWithCity() {
        return weatherForecastService.findWeatherForecastWithCity();
    }


    // 添加天气预测信息
    @PostMapping("/insert")
    public Integer insertWeatherForecast(@RequestBody WeatherForecast weatherForecast) {
        return weatherForecastService.insertWeatherForecast(weatherForecast);
    }

    // 修改天气预测信息
    @PutMapping("/update")
    public Integer updateWeatherForecast(@RequestBody WeatherForecast weatherForecast) {
        return weatherForecastService.updateWeatherForecast(weatherForecast);
    }

    // 根据ID删除天气预测信息
    @DeleteMapping("/del")
    public Integer deleteWeatherForecast(Integer forecast_id) {
        return weatherForecastService.deleteWeatherForecast(forecast_id);
    }


    /*
    // 根据城市名、省份、预测日期查询天气预测信息，但是我是通过前端筛选的数据，所以这个没必要
    @GetMapping("/by-city-and-date")
    public List<ViewWeatherForecastWithCity> findWeatherForecastByCityAndDate(String city_name, String province, Date forecast_date) {
        return weatherForecastService.findWeatherForecastByCityAndDate(city_name,province,forecast_date);
    }*/


}//1